package com.sg.service.base.app.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sg.common.util.CommonFunctionHelper;
import com.sg.dto.base.app.req.QueryAppraiserWsetDetailListReq;
import com.sg.entity.OmsEvaluationTemplateEvaluationSet;
import com.sg.service.base.app.MOmsEvaluationTemplateEvaluationSetService;
import com.wicket.okrapp.common.dto.FieldInfo;
import com.wicket.okrapp.common.exception.BizException;
import com.wicket.okrapp.dal.mapper.mbg.OmsEvaluationTemplateEvaluationSetMapper;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * @author ：
 * @version 1.0
 * @since 2022/1/19 15:39
 */
@Service
public class MOmsEvaluationTemplateEvaluationSetServiceImpl
        extends ServiceImpl<OmsEvaluationTemplateEvaluationSetMapper, OmsEvaluationTemplateEvaluationSet>
        implements MOmsEvaluationTemplateEvaluationSetService {

    @Autowired
    OmsEvaluationTemplateEvaluationSetMapper omsEvaluationTemplateEvaluationSetMapper;

    /**
     * 3-3-14新增评价模板评价设置[3226]
     * gen by moon at 10/10/2022, 1:27:18 AM
     */
    @Trace(operationName = "3-3-14新增评价模板评价设置")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public String addEvaTempEvaSet(OmsEvaluationTemplateEvaluationSet omsEvaluationTemplateEvaluationSet) {
        omsEvaluationTemplateEvaluationSet.setEvaTempEvaSetId(CommonFunctionHelper.getUid());//DISTRIBUTED_ID
        omsEvaluationTemplateEvaluationSet.setBatchEndtTime(CommonFunctionHelper.getFutureTime());//FUTURE_CURRENT_TIME
        omsEvaluationTemplateEvaluationSet.setIsUpdate("TRUE");
        omsEvaluationTemplateEvaluationSet.setUpdateStatus("NEW");
        omsEvaluationTemplateEvaluationSet.setArchivngType("NOT_ARCHIVE");
        omsEvaluationTemplateEvaluationSet.setIsEditing("TRUE");
        omsEvaluationTemplateEvaluationSet.setIsArchive("FALSE");
        omsEvaluationTemplateEvaluationSet.setSubjectLifeCycle("EDITING");
        omsEvaluationTemplateEvaluationSet.setOperationInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID
        omsEvaluationTemplateEvaluationSet.setCreateInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID
        omsEvaluationTemplateEvaluationSet.setOperateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
        omsEvaluationTemplateEvaluationSet.setCreateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
        omsEvaluationTemplateEvaluationSet.setIsValid("FALSE");
        omsEvaluationTemplateEvaluationSet.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID
        omsEvaluationTemplateEvaluationSet.setAppId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecAppId());//CURRENT_APPID
        if (super.save(omsEvaluationTemplateEvaluationSet)) {
            return omsEvaluationTemplateEvaluationSet.getEvaTempEvaSetId();
        } else {
            return "-1";
        }

    }

    /**
     * 3-3-14查询评价人权重设置明细列表[3269]
     * gen by moon at 8/31/2022, 2:23:43 AM
     */
    @Trace(operationName = "3-3-14查询评价人权重设置明细列表")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public List<OmsEvaluationTemplateEvaluationSet> queryAppraiserWsetDetailList(QueryAppraiserWsetDetailListReq reqDto) {
        return null; //todo ruizhe dong
    }

    /**
     * 3-3-14查询评价模板评价设置列表[4219]
     * gen by moon at 10/10/2022, 1:27:18 AM
     */
    @Trace(operationName = "3-3-14查询评价模板评价设置列表")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public List<OmsEvaluationTemplateEvaluationSet> queryEvaTempEvaSetList(OmsEvaluationTemplateEvaluationSet omsEvaluationTemplateEvaluationSet) {

        try {
            QueryWrapper<OmsEvaluationTemplateEvaluationSet> queryWrapper = new QueryWrapper<>();


            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(omsEvaluationTemplateEvaluationSet);
            List<FieldInfo> compareList = CommonFunctionHelper.getRangeField(OmsEvaluationTemplateEvaluationSet.class);
            CommonFunctionHelper.buildQueryWrapperCompare(queryWrapper, compareList, fieldInfoMap);
            List<FieldInfo> likeList = CommonFunctionHelper.getLikeFiled(OmsEvaluationTemplateEvaluationSet.class);
            CommonFunctionHelper.buildQueryWrapperLike(queryWrapper, likeList, fieldInfoMap);
            likeList.addAll(compareList);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap, likeList);
            List<FieldInfo> orderList = CommonFunctionHelper.getOrderList(OmsEvaluationTemplateEvaluationSet.class);
            //CommonFunctionHelper.buildQueryWrapperOrder(queryWrapper, orderList);

            return ((List<OmsEvaluationTemplateEvaluationSet>) super.list(queryWrapper));
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1", e, false);
        }
    }

    /**
     * 3-3-14批量删评价模板评价设置[4221]
     * gen by moon at 10/10/2022, 1:27:19 AM
     */
    @Trace(operationName = "3-3-14批量删评价模板评价设置")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean batchDeleteEvaTempEvaSet(List<String> reqDto) {

        if (reqDto == null || reqDto.size() == 0) {
            return false;
        }

        return super.removeByIds(reqDto);
    }

}

